import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  //  首页入口
  {
    path: "/",
    name: "home",
    redirect: "/base-city",
  },
  {
    path: "/base-city",
    name: "base-city",
    component: () => import("../views/base-city/index.vue"),
    meta: {
      title: "加载动画、流光、扩散波",
    },
  },
  {
    path: "/effect-city",
    name: "effect-city",
    component: () => import("../views/effect-city/index.vue"),
    meta: {
      title: "飞线，圆形扫描，扩散墙",
    },
  },
  {
    path: "/surround-line-city",
    name: "surround-line-city",
    component: () => import("../views/surround-line-city/index.vue"),
    meta: {
      title: "包围线以及其上的扫光",
    },
  },
  {
    path: "/models",
    name: "models",
    component: () => import("../views/models/index.vue"),
    meta: {
      title: "模型",
    },
  },
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  } else {
    document.title = "首页";
  }
  next();
});

const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch((err) => err);
};

export default router;
